import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { usePermissStore } from '../store/permiss';
import Home from '../views/home.vue';

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/dashboard2',
                name: 'dashboard2',
                meta: {
                    title: '图书系统首页',
                },
                component: () => import(/* webpackChunkName: "dashboard" */ '../views/user/dashboard2.vue'),
            },
            {
                path: '/person',
                name: 'person',
                meta: {
                    title: '个人中心',
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/user/person.vue'),
            },
            {
                path: '/user',
                name: 'user',
                meta: {
                    title: '用户管理',
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/user/user.vue'),
            },
            {
                path: '/menu',
                name: 'menu',
                meta: {
                    title: '菜单管理',
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/user/menu.vue'),
            },
            {
                path: '/role',
                name: 'role',
                meta: {
                    title: '角色管理',
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/user/role.vue'),
            }
        ],
    },
    {
        path: '/login',
        name: 'Login',
        meta: {
            title: '登录',
        },
        component: () => import(/* webpackChunkName: "login" */ '../views/user/login.vue'),
    },
    {
        path: '/register',
        name: 'register',
        meta: {
            title: '注册',
        },
        component: () => import(/* webpackChunkName: "login" */ '../views/user/register.vue'),
    },
    {
        path: '/403',
        name: '403',
        meta: {
            title: '没有权限',
        },
        component: () => import(/* webpackChunkName: "403" */ '../views/exception/403.vue'),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-manage-system`;
     next();
});

export default router;
